<template>
  <fl-navBar
    dark
    :border="false"
    title="听课评价"
    left-icon="left"
    color="#333333"
    :fixed="true"
    background-color="#fff"
    status-bar
  />
  <view class="courseEvaluateDetail">
    <view class="coursecontent">
      <uni-collapse v-model="openInfo" ref="collapse">
        <uni-collapse-item
          name="1"
          border
          class="collapse-item"
          title-border="none"
          :border="false"
        >
          <template v-slot:title>
            <view class="doc_msg">
              <text class="line"></text>
              <text class="doc_title">基础信息</text>
            </view>
          </template>
          <view class="detail_content">
            <view class="detail_item">
              <text class="item_key">任务名称</text>
              <text class="item_value">{{ form.taskName }}</text>
            </view>
            <view class="detail_item">
              <text class="item_key">责任人</text>
              <text class="item_value">{{ form.masterName }}</text>
            </view>
            <view class="detail_item">
              <text class="item_key">执行人</text>
              <text class="item_value">{{ form.executorName }}</text>
            </view>
            <view class="detail_item">
              <text class="item_key">到期时间</text>
              <text class="item_value">{{ form.expireDate }}</text>
            </view>
            <view class="detail_item">
              <text class="item_key">任务描述</text>
              <text class="item_value">{{ form.description }}</text>
            </view>
            <view class="detail_item" style="display: flex; flex-direction: column">
              <view class="item_key">附件</view>
              <view class="item_value">
                <fl-fileList
                  v-if="filePath.length > 0"
                  :closeShow="false"
                  :fileList="filePath"
                />
              </view>
            </view>
          </view>
        </uni-collapse-item>
      </uni-collapse>
      <view class="coursecontent_tabs" v-if="params.status === '1'">
        <fl-tabs
          :styleObj="{ fontSize: '28rpx' }"
          :current="current"
          @tabsChange="tabsChange"
          :list="list"
        />
        <view class="course_contentItem">
          <view class="zxqk" v-if="current == 0">
            <view class="zxqk_item" v-for="(ele, index) in subTaskList" :key="index">
              <view class="statusItem">
                <view class="playStstus">{{ getName(ele.approveStatus) }}</view>

                <image
                  v-if="ele.approveStatus === '0'"
                  class="statusImg"
                  mode="withFix"
                  src="@/static/images/app_center/pnone.png"
                  alt=""
                />
                <image
                  v-if="ele.approveStatus === '1'"
                  class="statusImg"
                  mode="withFix"
                  src="@/static/images/app_center/pdoing.png"
                  alt=""
                />
                <image
                  v-if="ele.approveStatus === '2'"
                  class="statusImg"
                  mode="withFix"
                  src="@/static/images/app_center/psuccess.png"
                  alt=""
                />
              </view>
              <view class="statustext">{{ ele.executorName }}</view>
            </view>
          </view>
          <view class="xq" v-if="current == 1">
            <subList :list="subTaskList" />
          </view>
        </view>
      </view>
      <!-- 校园巡视信息 -->
      <view class="schoolxunshi" v-if="params.status === '2'">
        <view class="doc_msg">
          <text class="line"></text>
          <text class="doc_title">校园巡视信息</text>
        </view>
        <view class="detail_item w710">
          <text class="item_key">巡视时间</text>
          <text class="item_value">{{ form.patrolDate }}</text>
        </view>
        <view class="detail_item w710">
          <text class="item_key">巡视情况及存在问题记录</text>
          <text class="item_value">{{ form.description }}</text>
        </view>
        <view class="detail_item w710">
          <text class="item_key">提出意见和建议</text>
          <text class="item_value">{{ form.feedback }}</text>
        </view>
        <view class="detail_item w710" style="display: flex; flex-direction: column">
          <view class="item_key">附件</view>
          <view class="item_value">
            <fl-fileList
              v-if="masterTaskInfoFiles.length > 0"
              :closeShow="false"
              :fileList="masterTaskInfoFiles"
            />
          </view>
          <view class="detail_item w710">
            <uni-forms
              style="width: 100%"
              label-width="80px"
              :rules="customRules"
              ref="valiForm"
              :modelValue="forms"
            >
              <uni-forms-item label="审核意见" required name="approveStatus">
                <uni-data-select
                  :clear="false"
                  v-model="forms.approveStatus"
                  :localdata="[
                    { text: '拒绝', value: '3' },
                    { text: '通过', value: '2' },
                  ]"
                ></uni-data-select>
              </uni-forms-item>
              <uni-forms-item label="审核建议" required name="approveReason">
                <uni-easyinput
                  :clearable="false"
                  type="textarea"
                  v-model="forms.approveReason"
                  placeholder="请输入审核建议"
                />
              </uni-forms-item>
            </uni-forms>
          </view>
          <view class="confire" :style="{ bottom: safeAreaInsets.bottom + 'px' }">
            <button style="width: 90%" type="primary" @click="submit('valiForm')">
              提交
            </button>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script setup>
import { ref, nextTick } from "vue";
import { onLoad, onShow } from "@dcloudio/uni-app";
import { fileUpload } from "@/api/http";
import { superviseTaskCheck } from "@/api/supervisionMaster/distribute";
import FileList from "@/pages/courseEvaluateDetail/fileList.vue";
import { getToken } from "@/utils/auth";
import { upload } from "@/utils/upload";
import subList from "@/pages/supervisionMasterLook/subList";
const { safeAreaInsets } = uni.getSystemInfoSync();
import modal from "@/plugins/modal";
const openInfo = ref(["1"]);

const current = ref(0);

const collapse = ref();
const valiForm = ref();
const subTaskList = ref([]);
const filePath = ref([]);
const masterTaskInfoFiles = ref([]);
const form = ref({});
const forms = ref({});
const params = ref({});
const list = ref([
  {
    id: 0,
    name: "执行人",
  },
  {
    id: 1,
    name: "子任务",
  },
]);
const customRules = {
  approveStatus: {
    rules: [
      {
        required: true,
        errorMessage: " ",
      },
    ],
  },
  approveReason: {
    rules: [
      {
        required: true,
        errorMessage: " ",
      },
    ],
  },
};
const getName = (status) => {
  // 审批状态：0.待接收，2进行中，1/3已完成
  switch (status) {
    // 空.待接收，0.进行中，1.已提交，2.审核通过，3.审核拒绝
    case "0":
      return "进行中";
    case "1":
      return "进行中";
    case "2":
      return "已完成";
    case "3":
      return "进行中";
    default:
      return "待接收";
  }
};
function tabsChange(index) {
  current.value = index;
}
function submit(ref) {
  valiForm.value
    .validate()
    .then(async (res) => {
      let par = {
        id: form.value.id,
        approveReason: forms.value.approveReason,
        approveStatus: forms.value.approveStatus,
      };
      await superviseTaskCheck(par);
      modal.msgSuccess("操作成功");
      setTimeout(() => {
        uni.navigateBack();
      }, 200);
    })
    .catch((err) => {
      modal.msgError("请填写必填项");
    });
}
async function getList() {
  let cur = uni.getStorageSync("courses");
  if (cur) {
    form.value = { ...cur };
    if (cur.subTaskList && cur.subTaskList.length > 0) {
      subTaskList.value = cur.subTaskList;
    }
    if (cur.filePath) {
      filePath.value = JSON.parse(cur.filePath);
    }
    // 校园巡视信息 附件
    if (cur.masterTaskInfo) {
      if (cur.masterTaskInfo.filePath) {
        masterTaskInfoFiles.value = JSON.parse(cur.masterTaskInfo.filePath);
      }
    }
  }
  nextTick(() => {
    collapse.value.resize();
  });
}

onLoad((options) => {
  params.value = options;
  getList();
});
</script>

<style lang="scss" scoped>
.confire {
  width: 100%;
  flex: 1;
  display: flex;
  justify-content: space-around;
  margin-top: 30rpx;
}
.w710 {
  width: 710rpx;
  margin: 0 auto;
  padding: 20rpx 10rpx;
}
.teachersfile {
  display: flex;
  flex-wrap: wrap;
}
page {
  display: flex;
  flex-direction: column;
}
.fileWrap {
  display: flex;
  flex-direction: column;
}
.confire {
  // position: fixed;
  // bottom: 0;
  // left: 0;
  width: 100%;
  flex: 1;
  display: flex;
  justify-content: space-around;
  margin-top: 30rpx;
}
.courseEvaluateDetail {
  height: 100%;
  overflow-y: scroll;
  background-color: #fff;
  .w710 {
    width: 710rpx;
    margin: 0 auto;
    padding: 20rpx 10rpx;
  }
  .detail_item {
    display: flex;
    padding: 20rpx 10rpx;
    background-color: #fff;
    border-bottom: 2rpx solid #ebedf0;

    .item_key,
    .item_value {
      color: #666666;
      font-size: 28rpx;
    }
    .item_key {
      width: 180rpx;
    }
    .item_value {
      flex: 1;
      color: #333333;
    }
  }
  .doc_msg {
    display: flex;
    align-items: center;
    height: 100rpx;
    font-size: 32rpx;
    font-weight: 700;
    color: #000;
    padding-left: 25rpx;

    .line {
      width: 6rpx;
      height: 30rpx;
      background-color: #2362a6;
      margin-right: 12rpx;
    }
  }
  .coursecontent {
    overflow-y: scroll;
    height: 100%;
  }
  .course_contentItem {
    margin-top: 40rpx;
  }
  .zxqk {
    display: flex;
    height: 100%;
    .zxqk_item {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      width: 25%;
      flex-wrap: wrap;
      .statustext {
        margin-top: 10rpx;
      }
      .statusItem {
        position: relative;
        width: 110rpx;
        height: 110rpx;
        border-radius: 50%;
        .playStstus {
          position: absolute;
          top: 50%;
          width: 100%;
          left: 50%;
          transform: translate(-50%, -50%);
          font-size: 24rpx;
          text-align: center;
        }
        .statusImg {
          width: 100%;
          height: 100%;
        }
      }
    }
  }
  .ddzfile {
    display: flex;
    flex-wrap: wrap;
    .ddzfile_item {
      display: flex;
      justify-content: center;
      width: 50%;
      margin-bottom: 30rpx;

      img {
        width: 60rpx;
        height: 66rpx;
        margin-right: 26rpx;
      }
      .pdfNamebox {
        .pdfName {
          width: 220rpx;
          overflow: hidden;
          white-space: nowrap;
          text-overflow: ellipsis;
        }
        .pdfSize {
          font-size: 24rpx;
          color: #3f3f3f;
          margin-top: 6rpx;
        }
      }
    }
  }
  .collapse-item {
    height: 100%;
    background-color: #fff;
    .detail_content {
      width: 710rpx;
      margin: 0 auto;
      background-color: #fff;
      .coursecontent_tabs {
        margin-top: 20rpx;
      }
      .appear_container {
        width: 710rpx;
        margin: 0 auto;
      }
    }
  }
}
</style>
